package com.susallwave.srcb.schedule;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class TaskDispatcher {
    @Autowired
    private Map<String, RetryDistributedLock> tasks;

    @Scheduled(cron = "0 20 2 * * ?") // 每天凌晨2点20分执行
    public void syncCbrcChart() {
        RetryDistributedLock task = tasks.get("syncCbrcChart");
        if (task != null) {
            task.run();
        }
    }

    @Scheduled(cron = "0 30 2 * * ?") // 每天凌晨2点30分执行
    public void syncGreenDataChart() {
        RetryDistributedLock task = tasks.get("syncGreenDataChart");
        if (task != null) {
            task.run();
        }
    }

    @Scheduled(cron = "0 40 2 * * ?") // 每天凌晨2点40分执行
    public void syncPbocChart() {
        RetryDistributedLock task = tasks.get("syncPbocChart");
        if (task != null) {
            task.run();
        }
    }

    @Scheduled(cron = "0 50 2 * * ?") // 每天凌晨2点50分执行
    public void syncEnvBenefit() {
        RetryDistributedLock task = tasks.get("syncEnvBenefit");
        if (task != null) {
            task.run();
        }
    }
}
